<template>
  <section>
    <el-form
      :model="loginForm"
      :rules="loginRules"
      label-position="left"
      ref="login"
      class="login-from login-container"
    >
      <h3 class="title">系统登录</h3>
      <el-form-item prop="account">
        <el-input type="text" v-model="loginForm.account" auto-complete="off" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item prop="pwd">
        <el-input type="password" v-model="loginForm.pwd" auto-complete="off" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item style="width:100%">
        <el-button
          type="primary"
          style="width:100%"
          @click.native.prevent="subLogin"
          :loading="logining"
        >登录</el-button>
        <!-- <el-button @click.native.prevent="handleReset2">重置</el-button> -->
      </el-form-item>
    </el-form>
  </section>
</template>
<script>
import { Login } from "../../api/user";
export default {
  data() {
    return {
      loginForm: {
        account: "",
        pwd: "",
        remember: false
      },
      loginRules: {
        account: [{ required: true, message: "请输入账号", trigger: "blur" }],
        checkPass: [{ required: true, message: "请输入密码", trigger: "blur" }]
      },
      logining: false
    };
  },
  methods: {
    subLogin(ev) {
      //   console.log("yes");
      this.$refs.login.validate(valid => {
        if (valid) {
          Login(this.loginForm).then(res => {
            sessionStorage.setItem("user", JSON.stringify(res.msg));
            this.$router.push({ path: "/home" });
          });
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.login-container {
  -webkit-border-radius: 5px;
  border-radius: 5px;
  -moz-border-radius: 5px;
  background-clip: padding-box;
  margin: 18px auto;
  width: 350px;
  padding: 35px 35px 15px 35px;
  background: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
  .title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
  }
  .remember {
    margin: 0px 0px 35px 0px;
  }
}
</style>
